package com.kunbo.cn.service.impl.core.purchase;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import com.kunbo.cn.dao.core.purchase.ModulationPriceHistoryDao;
import com.kunbo.cn.dto.ModulationPriceHistoryDto;
import com.kunbo.cn.entity.core.purchase.ModulationPriceHistory;
import com.kunbo.cn.service.core.purchase.ModulationPriceHistoryService;

@Service
public class ModulationPriceHistoryImpl implements ModulationPriceHistoryService {

	@Autowired
	private ModulationPriceHistoryDao dao;

	@Autowired
	private JdbcTemplate jdbc;

	@Override
	public boolean save(String uuid, String create_user_id, String taskid, double original_price, double new_price,
			String adjustment_time,String order_code) {
		// TODO Auto-generated method stub
		ModulationPriceHistory modulationPrice = new ModulationPriceHistory();
		modulationPrice.setUuid(uuid);
		modulationPrice.setCreate_user_id(create_user_id);
		modulationPrice.setTaskid(taskid);
		modulationPrice.setOriginal_price(original_price);
		modulationPrice.setNew_price(new_price);
		modulationPrice.setAdjustment_time(adjustment_time);
		modulationPrice.setOrder_code(order_code);
		modulationPrice = dao.save(modulationPrice);
		if(modulationPrice != null)
			return true;
		else
			return false;
	}

	@Override
	public List<ModulationPriceHistoryDto> get(String order_code) {
		// TODO Auto-generated method stub
		List<ModulationPriceHistoryDto> dto = new ArrayList<ModulationPriceHistoryDto>();
		String sql = "select * from business_price_adjustment_history where order_code = '" + order_code + "'";
		List<Map<String, Object>>  list = jdbc.queryForList(sql);
		for (Map<String, Object> map : list) {
			ModulationPriceHistoryDto price = new ModulationPriceHistoryDto();
			sql = "select * from sys_user where id = '" + map.get("create_user_id").toString() + "'";
			Map<String, Object> user = jdbc.queryForMap(sql);
			price.setModulationPrice(map);
			price.setUser(user);
			dto.add(price);
		}
		return dto;
	}

}
